package EjercicioExamen;

public class Producto {

	private String name;
	private double price;
	private double profit;
	private int prodState;
	private double percent;
	
	public static final int USUAL_PROD = 0;
	public static final int GIFT = 1;
	public static final int OFFER = 2;
	public static final int STOCK = 3;
	
	public Producto() {
		this.name = "";
		this.price = 0;
		this.profit = 0;
		this.prodState = 0;
		this.percent = 0;
	}
	
	public Producto(String name, double price, int prodState) {
		this.name = name;
		this.price = price;
		this.prodState = prodState;
		AssignStateToProd();
	}
	
	public String GetName() {
		return name;
	}
	
	public double GetPrice() {
		return price;
	}
	
	public double GetProfit() {
		return profit;
	}
	
	public double GetPercent() {
		return percent;
	}

	private void AssignStateToProd() {
		switch (prodState) {
			case USUAL_PROD:
				profit = price*0.03;
				percent = 3.0;
				break;
			case GIFT:
				if (price<=20) {
					profit = 0;
					percent = 0.0;
				} else {
					profit = price*0.01;
					percent = 1.0;
				}
				break;
			case OFFER:
				if (price<=10) {
					profit = price*0.01;
					percent = 1.0;
				} else {
					if (price<=20) {
						profit = price*0.02;
						percent = 2.0;
					} else {
						profit = price*0.03;
						percent = 3.0;
					}
				}
				break;
			case STOCK:
				if (price<=50) {
					profit = price*0.05;
					percent = 5.0;
				} else {
					if (price<=100) {
						profit = price*0.1;
						percent = 10.0;
					} else {
						profit = price*0.12;
						percent = 12.0;
					}
				}
				break;
			default:
				System.err.print("No state selected for product "+name+".\n");
		}
	}
}
